package cn.wolfcode.rbac.web.intercptor;

import cn.wolfcode.rbac.domain.Employee;
import cn.wolfcode.rbac.util.CurrentUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @version 1.0
 * @Author:Cao Zhijian
 * @DATE:2020/12/27 0027 20:55:54
 */
@Component
public class CheckLoginIntercptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        Employee current = CurrentUtil.getCurrent();
        if(current == null){
            response.sendRedirect("/login.html");
            return false;
        }else {
            return true;
        }
    }
}
